const Koa = require("koa");
const static = require("koa-static");
const views = require("koa-views");
const router = require("./routers/router");
const logger = require("koa-logger");
const body = require("koa-body");
const {join} = require("path");
const session = require("koa-session");
const adminInit = require("./control/adminInit");

// 生成 koa 实例
const app = new Koa;

// session 的配置对象
app.keys = ["心理健康检测系统"];

const CONFIG = {
    key: "Sid",
    maxAge: 10000,
    overwrite: true,
    httpOnly: true,
    //rolling: true
};

// 注册日志模块
app.use(logger());

// 注册 session
app.use(session(CONFIG, app));

// 配置 koa-body 处理 post 请求数据
app.use(body());

//配置静态资源目录
app.use(static(join(__dirname, "public")));

// 配置 pug 模板
app.use(views(join(__dirname, "views"), {
    extension: "html"
}));

// 注册路由信息
app.use(router.routes()).use(router.allowedMethods());

app.listen(80, () => {
    console.log("服务器已启动");
});

adminInit.adminInit
